
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>操作DOM · JavaScript学习</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Veng">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-pageview-count/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="修改DOM结构.html" />
    
    
    <link rel="prev" href="查找和过滤.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../基础/基础.html">
            
                <a href="../基础/基础.html">
            
                    
                    基础
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../基础/变量.html">
            
                <a href="../基础/变量.html">
            
                    
                    数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../基础/let和const命令.html">
            
                <a href="../基础/let和const命令.html">
            
                    
                    let和const命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../基础/数值.html">
            
                <a href="../基础/数值.html">
            
                    
                    数值
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../基础/字符串.html">
            
                <a href="../基础/字符串.html">
            
                    
                    字符串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../基础/对象.html">
            
                <a href="../基础/对象.html">
            
                    
                    对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../基础/数组.html">
            
                <a href="../基础/数组.html">
            
                    
                    数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="../基础/Symbol.html">
            
                <a href="../基础/Symbol.html">
            
                    
                    Symbol
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="../基础/函数.html">
            
                <a href="../基础/函数.html">
            
                    
                    函数
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.8.1" data-path="../基础/函数的扩展.html">
            
                <a href="../基础/函数的扩展.html">
            
                    
                    函数的扩展
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.2" data-path="../基础/变量的解构赋值.html">
            
                <a href="../基础/变量的解构赋值.html">
            
                    
                    变量作用域与解构赋值
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.3" data-path="../基础/函数3.html">
            
                <a href="../基础/函数3.html">
            
                    
                    方法函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.4" data-path="../基础/高阶函数.html">
            
                <a href="../基础/高阶函数.html">
            
                    
                    高阶函数
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.8.4.1" data-path="../基础/map-reduce.html">
            
                <a href="../基础/map-reduce.html">
            
                    
                    map/reduce
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.4.2" data-path="../基础/filter.html">
            
                <a href="../基础/filter.html">
            
                    
                    filter
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.4.3" data-path="../基础/sort.html">
            
                <a href="../基础/sort.html">
            
                    
                    sort
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.4.4" data-path="../基础/array其他方法.html">
            
                <a href="../基础/array其他方法.html">
            
                    
                    array其他方法
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.8.5" data-path="../基础/闭包.html">
            
                <a href="../基础/闭包.html">
            
                    
                    闭包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.6" data-path="../基础/箭头函数.html">
            
                <a href="../基础/箭头函数.html">
            
                    
                    箭头函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.7" data-path="../浏览器/Promise.html">
            
                <a href="../浏览器/Promise.html">
            
                    
                    Promise
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.8" data-path="../基础/generator.html">
            
                <a href="../基础/generator.html">
            
                    
                    generator
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.9" data-path="../基础/async.html">
            
                <a href="../基础/async.html">
            
                    
                    async
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.9" data-path="../基础/标准对象.html">
            
                <a href="../基础/标准对象.html">
            
                    
                    标准对象
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.9.1" data-path="../基础/SetMap.html">
            
                <a href="../基础/SetMap.html">
            
                    
                    Set,Map
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9.2" data-path="../基础/Date.html">
            
                <a href="../基础/Date.html">
            
                    
                    Date
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9.3" data-path="../基础/Math.html">
            
                <a href="../基础/Math.html">
            
                    
                    Math
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9.4" data-path="../基础/Proxy.html">
            
                <a href="../基础/Proxy.html">
            
                    
                    Proxy
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9.5" data-path="../基础/RepExp.html">
            
                <a href="../基础/RepExp.html">
            
                    
                    正则表达式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9.6" data-path="../基础/正则表达式.html">
            
                <a href="../基础/正则表达式.html">
            
                    
                    正则表达式别篇
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9.7" data-path="../基础/json.html">
            
                <a href="../基础/json.html">
            
                    
                    JSON
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.10" data-path="../基础/面向对象编程.html">
            
                <a href="../基础/面向对象编程.html">
            
                    
                    面向对象编程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.10.1" data-path="../基础/对象的扩展.html">
            
                <a href="../基础/对象的扩展.html">
            
                    
                    对象的扩展
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10.2" data-path="../基础/创建对象.html">
            
                <a href="../基础/创建对象.html">
            
                    
                    创建对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10.3" data-path="../基础/原型继承.html">
            
                <a href="../基础/原型继承.html">
            
                    
                    原型继承
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10.4" data-path="../基础/class继承.html">
            
                <a href="../基础/class继承.html">
            
                    
                    class继承
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10.5" data-path="../基础/模块化Module.html">
            
                <a href="../基础/模块化Module.html">
            
                    
                    模块化Module
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.11" data-path="../基础/异常处理.html">
            
                <a href="../基础/异常处理.html">
            
                    
                    异常处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.12" data-path="../基础/编程风格.html">
            
                <a href="../基础/编程风格.html">
            
                    
                    编程风格
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../js扩展/js扩展.html">
            
                <a href="../js扩展/js扩展.html">
            
                    
                    js 扩展
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../js扩展/字符串.html">
            
                <a href="../js扩展/字符串.html">
            
                    
                    字符串
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../浏览器/浏览器.html">
            
                <a href="../浏览器/浏览器.html">
            
                    
                    浏览器
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../浏览器/浏览器对象.html">
            
                <a href="../浏览器/浏览器对象.html">
            
                    
                    浏览器对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../浏览器/操作DOM.html">
            
                <a href="../浏览器/操作DOM.html">
            
                    
                    操作DOM
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.2.1" data-path="../浏览器/更新DOM.html">
            
                <a href="../浏览器/更新DOM.html">
            
                    
                    更新DOM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.2" data-path="../浏览器/插入DOM.html">
            
                <a href="../浏览器/插入DOM.html">
            
                    
                    插入DOM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.3" data-path="../浏览器/删除DOM.html">
            
                <a href="../浏览器/删除DOM.html">
            
                    
                    删除DOM
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../浏览器/DOM事件.html">
            
                <a href="../浏览器/DOM事件.html">
            
                    
                    DOM事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../浏览器/操作表单.html">
            
                <a href="../浏览器/操作表单.html">
            
                    
                    操作表单
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../浏览器/操作文件.html">
            
                <a href="../浏览器/操作文件.html">
            
                    
                    操作文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../浏览器/AJAX.html">
            
                <a href="../浏览器/AJAX.html">
            
                    
                    AJAX
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../浏览器/Canvas.html">
            
                <a href="../浏览器/Canvas.html">
            
                    
                    Canvas
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="jquery.html">
            
                <a href="jquery.html">
            
                    
                    Jquery
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="选择器.html">
            
                <a href="选择器.html">
            
                    
                    选择器
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1.1" data-path="层级选择器.html">
            
                <a href="层级选择器.html">
            
                    
                    层级选择器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.1.2" data-path="查找和过滤.html">
            
                <a href="查找和过滤.html">
            
                    
                    查找和过滤
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter active" data-level="1.5.2" data-path="操作DOM.html">
            
                <a href="操作DOM.html">
            
                    
                    操作DOM
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.2.1" data-path="修改DOM结构.html">
            
                <a href="修改DOM结构.html">
            
                    
                    修改DOM结构
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="事件.html">
            
                <a href="事件.html">
            
                    
                    事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="动画.html">
            
                <a href="动画.html">
            
                    
                    动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="AJAX.html">
            
                <a href="AJAX.html">
            
                    
                    AJAX
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="扩展.html">
            
                <a href="扩展.html">
            
                    
                    扩展
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../nodejs/nodejs.html">
            
                <a href="../nodejs/nodejs.html">
            
                    
                    Nodejs
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../nodejs/模块.html">
            
                <a href="../nodejs/模块.html">
            
                    
                    模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../nodejs/path.html">
            
                <a href="../nodejs/path.html">
            
                    
                    path
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../nodejs/文件操作.html">
            
                <a href="../nodejs/文件操作.html">
            
                    
                    文件操作 fs
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../nodejs/流Stream.html">
            
                <a href="../nodejs/流Stream.html">
            
                    
                    流Stream
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../nodejs/zlib压缩解压缩.html">
            
                <a href="../nodejs/zlib压缩解压缩.html">
            
                    
                    zlib压缩解压缩
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../nodejs/net网络.html">
            
                <a href="../nodejs/net网络.html">
            
                    
                    net网络
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../nodejs/http.html">
            
                <a href="../nodejs/http.html">
            
                    
                    http
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../nodejs/express框架.html">
            
                <a href="../nodejs/express框架.html">
            
                    
                    express框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="../nodejs/process进程.html">
            
                <a href="../nodejs/process进程.html">
            
                    
                    process 进程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.10" data-path="../nodejs/child_process.html">
            
                <a href="../nodejs/child_process.html">
            
                    
                    child_process
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.11" data-path="../nodejs/os.html">
            
                <a href="../nodejs/os.html">
            
                    
                    os-操作系统
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../react/react.html">
            
                <a href="../react/react.html">
            
                    
                    React
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >操作DOM</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x64CD;&#x4F5C;dom">&#x64CD;&#x4F5C;DOM</h1>
<p>jQuery&#x7684;&#x9009;&#x62E9;&#x5668;&#x5F88;&#x5F3A;&#x5927;&#xFF0C;&#x7528;&#x8D77;&#x6765;&#x53C8;&#x7B80;&#x5355;&#x53C8;&#x7075;&#x6D3B;&#xFF0C;&#x4F46;&#x662F;&#x641E;&#x4E86;&#x8FD9;&#x4E48;&#x4E45;&#xFF0C;&#x6211;&#x62FF;&#x5230;&#x4E86;jQuery&#x5BF9;&#x8C61;&#xFF0C;&#x5230;&#x5E95;&#x8981;&#x5E72;&#x4EC0;&#x4E48;&#xFF1F;</p>
<p>&#x7B54;&#x6848;&#x5F53;&#x7136;&#x662F;&#x64CD;&#x4F5C;&#x5BF9;&#x5E94;&#x7684;DOM&#x8282;&#x70B9;&#x5566;&#xFF01;</p>
<p>&#x56DE;&#x987E;&#x4E00;&#x4E0B;&#x4FEE;&#x6539;DOM&#x7684;CSS&#x3001;&#x6587;&#x672C;&#x3001;&#x8BBE;&#x7F6E;HTML&#x6709;&#x591A;&#x4E48;&#x9EBB;&#x70E6;&#xFF0C;&#x800C;&#x4E14;&#x6709;&#x7684;&#x6D4F;&#x89C8;&#x5668;&#x53EA;&#x6709;innerHTML&#xFF0C;&#x6709;&#x7684;&#x6D4F;&#x89C8;&#x5668;&#x652F;&#x6301;innerText&#xFF0C;&#x6709;&#x4E86;jQuery&#x5BF9;&#x8C61;&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x8003;&#x8651;&#x6D4F;&#x89C8;&#x5668;&#x5DEE;&#x5F02;&#x4E86;&#xFF0C;&#x5168;&#x90E8;&#x7EDF;&#x4E00;&#x64CD;&#x4F5C;&#xFF01;</p>
<p><font color="red">&#x6CE8;&#x610F;</font>,&#x5982;&#x679C;&#x662F;&#x4ECE;&#x5916;&#x90E8;&#x5F15;&#x5165;js&#x6587;&#x4EF6;&#xFF0C;&#x5F15;&#x5165;&#x653E;&#x5728;head&#x8DDF;&#x653E;&#x5728;body&#x4E24;&#x4E2A;&#x5730;&#x65B9;&#x662F;&#x4E0D;&#x4E00;&#x6837;&#x7684;&#xFF0C;body&#x7684;&#x4F1A;&#x8FDB;&#x884C;&#x5BF9;&#x9875;&#x9762;&#x7684;&#x521D;&#x59CB;&#x5316;&#xFF0C;&#x4F46;&#x662F;head&#x7684;&#x4E0D;&#x4F1A;,&#x6240;&#x4EE5;&#x4F60;&#x5C06;js&#x5728;head&#x5904;&#x5F15;&#x5165;&#x53D1;&#x73B0;&#x4EE3;&#x7801;&#x6CA1;&#x6709;&#x751F;&#x6548;&#x5C31;&#x662F;&#x8FD9;&#x4E2A;&#x539F;&#x56E0;&#xFF0C;head&#x91CC;&#x6709;&#x6548;&#x7684;&#x662F;&#x89E6;&#x53D1;&#x3002;&#x5982;&#x679C;&#x60F3;&#x8981;&#x653E;&#x5728;head&#x521D;&#x59CB;&#x5316;&#x4E5F;&#x6709;&#x529E;&#x6CD5;,&#x5728;&#x540E;&#x9762;&#x7684;<a href="&#x4E8B;&#x4EF6;.html">&#x4E8B;&#x4EF6;</a>&#x4F1A;&#x6D89;&#x53CA;&#x3002;</p>
<h3 id="&#x4FEE;&#x6539;text&#x548C;html">&#x4FEE;&#x6539;Text&#x548C;HTML</h3>
<p>jQuery&#x5BF9;&#x8C61;&#x7684;<code>text()</code>&#x548C;<code>html()</code>&#x65B9;&#x6CD5;&#x5206;&#x522B;&#x83B7;&#x53D6;&#x8282;&#x70B9;&#x7684;&#x6587;&#x672C;&#x548C;&#x539F;&#x59CB;HTML&#x6587;&#x672C;&#xFF0C;&#x4F8B;&#x5982;&#xFF0C;&#x5982;&#x4E0B;&#x7684;HTML&#x7ED3;&#x6784;&#xFF1A;</p>
<pre><code class="lang-html"><span class="hljs-comment">&lt;!-- HTML&#x7ED3;&#x6784; --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;test-ul&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;js&quot;</span>&gt;</span>JavaScript<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;book&quot;</span>&gt;</span>Java &amp;amp; JavaScript<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
</code></pre>
<p>&#x5206;&#x522B;&#x83B7;&#x53D6;&#x6587;&#x672C;&#x548C;HTML&#xFF1A;</p>
<pre><code class="lang-javascript">$(<span class="hljs-string">&apos;#test-ul li[name=book]&apos;</span>).text(); <span class="hljs-comment">// &apos;Java &amp; JavaScript&apos;</span>
$(<span class="hljs-string">&apos;#test-ul li[name=book]&apos;</span>).html(); <span class="hljs-comment">// &apos;Java &amp;amp; JavaScript&apos;</span>
</code></pre>
<p>&#x4E00;&#x4E2A;jQuery&#x5BF9;&#x8C61;&#x53EF;&#x4EE5;&#x5305;&#x542B;0&#x4E2A;&#x6216;&#x4EFB;&#x610F;&#x4E2A;DOM&#x5BF9;&#x8C61;&#xFF0C;&#x5B83;&#x7684;&#x65B9;&#x6CD5;&#x5B9E;&#x9645;&#x4E0A;&#x4F1A;&#x4F5C;&#x7528;&#x5728;&#x5BF9;&#x5E94;&#x7684;&#x6BCF;&#x4E2A;DOM&#x8282;&#x70B9;&#x4E0A;&#x3002;&#x5728;&#x4E0A;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#x4E2D;&#x8BD5;&#x8BD5;&#xFF1A;</p>
<pre><code class="lang-javascript">$(<span class="hljs-string">&apos;#test-ul li&apos;</span>).text(<span class="hljs-string">&apos;JS&apos;</span>); <span class="hljs-comment">// &#x662F;&#x4E0D;&#x662F;&#x4E24;&#x4E2A;&#x8282;&#x70B9;&#x90FD;&#x53D8;&#x6210;&#x4E86;JS&#xFF1F;</span>
</code></pre>
<p>&#x6240;&#x4EE5;jQuery&#x5BF9;&#x8C61;&#x7684;&#x53E6;&#x4E00;&#x4E2A;&#x597D;&#x5904;&#x662F;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x6267;&#x884C;&#x4E00;&#x4E2A;&#x64CD;&#x4F5C;&#xFF0C;&#x4F5C;&#x7528;&#x5728;&#x5BF9;&#x5E94;&#x7684;&#x4E00;&#x7EC4;DOM&#x8282;&#x70B9;&#x4E0A;&#x3002;&#x5373;&#x4F7F;&#x9009;&#x62E9;&#x5668;&#x6CA1;&#x6709;&#x8FD4;&#x56DE;&#x4EFB;&#x4F55;DOM&#x8282;&#x70B9;&#xFF0C;&#x8C03;&#x7528;jQuery&#x5BF9;&#x8C61;&#x7684;&#x65B9;&#x6CD5;&#x4ECD;&#x7136;&#x4E0D;&#x4F1A;&#x62A5;&#x9519;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x5982;&#x679C;&#x4E0D;&#x5B58;&#x5728;id&#x4E3A;not-exist&#x7684;&#x8282;&#x70B9;&#xFF1A;</span>
$(<span class="hljs-string">&apos;#not-exist&apos;</span>).text(<span class="hljs-string">&apos;Hello&apos;</span>); <span class="hljs-comment">// &#x4EE3;&#x7801;&#x4E0D;&#x62A5;&#x9519;&#xFF0C;&#x6CA1;&#x6709;&#x8282;&#x70B9;&#x88AB;&#x8BBE;&#x7F6E;&#x4E3A;&apos;Hello&apos;</span>
</code></pre>
<p>&#x8FD9;&#x610F;&#x5473;&#x7740;jQuery&#x5E2E;&#x4F60;&#x514D;&#x53BB;&#x4E86;&#x8BB8;&#x591A;<code>if</code>&#x8BED;&#x53E5;&#x3002;</p>
<h3 id="&#x4FEE;&#x6539;css">&#x4FEE;&#x6539;CSS</h3>
<p>jQuery&#x5BF9;&#x8C61;&#x6709;&#x201C;&#x6279;&#x91CF;&#x64CD;&#x4F5C;&#x201D;&#x7684;&#x7279;&#x70B9;&#xFF0C;&#x8FD9;&#x7528;&#x4E8E;&#x4FEE;&#x6539;CSS&#x5B9E;&#x5728;&#x662F;&#x592A;&#x65B9;&#x4FBF;&#x4E86;&#x3002;&#x8003;&#x8651;&#x4E0B;&#x9762;&#x7684;HTML&#x7ED3;&#x6784;&#xFF1A;</p>
<pre><code class="lang-html"><span class="hljs-comment">&lt;!-- HTML&#x7ED3;&#x6784; --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;test-css&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;lang dy&quot;</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>JavaScript<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;lang&quot;</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>Java<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;lang dy&quot;</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>Python<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;lang&quot;</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>Swift<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;lang dy&quot;</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>Scheme<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
</code></pre>
<p>&#x8981;&#x9AD8;&#x4EAE;&#x663E;&#x793A;&#x52A8;&#x6001;&#x8BED;&#x8A00;&#xFF0C;&#x8C03;&#x7528;jQuery&#x5BF9;&#x8C61;&#x7684;<code>css(&apos;name&apos;, &apos;value&apos;)</code>&#x65B9;&#x6CD5;&#xFF0C;&#x6211;&#x4EEC;&#x7528;&#x4E00;&#x884C;&#x8BED;&#x53E5;&#x5B9E;&#x73B0;&#xFF1A;</p>
<pre><code class="lang-javascript">$(<span class="hljs-string">&apos;#test-css li.dy&gt;span&apos;</span>).css(<span class="hljs-string">&apos;background-color&apos;</span>, <span class="hljs-string">&apos;#ffd351&apos;</span>).css(<span class="hljs-string">&apos;color&apos;</span>, <span class="hljs-string">&apos;red&apos;</span>);
</code></pre>
<p><em>&#x6CE8;&#x610F;</em>&#xFF0C;jQuery&#x5BF9;&#x8C61;&#x7684;&#x6240;&#x6709;&#x65B9;&#x6CD5;&#x90FD;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;jQuery&#x5BF9;&#x8C61;&#xFF08;&#x53EF;&#x80FD;&#x662F;&#x65B0;&#x7684;&#x4E5F;&#x53EF;&#x80FD;&#x662F;&#x81EA;&#x8EAB;&#xFF09;&#xFF0C;&#x8FD9;&#x6837;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x8FDB;&#x884C;&#x94FE;&#x5F0F;&#x8C03;&#x7528;&#xFF0C;&#x975E;&#x5E38;&#x65B9;&#x4FBF;&#x3002;</p>
<p>jQuery&#x5BF9;&#x8C61;&#x7684;<code>css()</code>&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x8FD9;&#x4E48;&#x7528;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> div = $(<span class="hljs-string">&apos;#test-div&apos;</span>);
div.css(<span class="hljs-string">&apos;color&apos;</span>); <span class="hljs-comment">// &apos;#000033&apos;, &#x83B7;&#x53D6;CSS&#x5C5E;&#x6027;</span>
div.css(<span class="hljs-string">&apos;color&apos;</span>, <span class="hljs-string">&apos;#336699&apos;</span>); <span class="hljs-comment">// &#x8BBE;&#x7F6E;CSS&#x5C5E;&#x6027;</span>
div.css(<span class="hljs-string">&apos;color&apos;</span>, <span class="hljs-string">&apos;&apos;</span>); <span class="hljs-comment">// &#x6E05;&#x9664;CSS&#x5C5E;&#x6027;</span>
</code></pre>
<p>&#x4E3A;&#x4E86;&#x548C;JavaScript&#x4FDD;&#x6301;&#x4E00;&#x81F4;&#xFF0C;CSS&#x5C5E;&#x6027;&#x53EF;&#x4EE5;&#x7528;<code>&apos;background-color&apos;</code>&#x548C;<code>&apos;backgroundColor&apos;</code>&#x4E24;&#x79CD;&#x683C;&#x5F0F;&#x3002;</p>
<p><code>css()</code>&#x65B9;&#x6CD5;&#x5C06;&#x4F5C;&#x7528;&#x4E8E;DOM&#x8282;&#x70B9;&#x7684;<code>style</code>&#x5C5E;&#x6027;&#xFF0C;&#x5177;&#x6709;&#x6700;&#x9AD8;&#x4F18;&#x5148;&#x7EA7;&#x3002;&#x5982;&#x679C;&#x8981;&#x4FEE;&#x6539;<code>class</code>&#x5C5E;&#x6027;&#xFF0C;&#x53EF;&#x4EE5;&#x7528;jQuery&#x63D0;&#x4F9B;&#x7684;&#x4E0B;&#x5217;&#x65B9;&#x6CD5;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> div = $(<span class="hljs-string">&apos;#test-div&apos;</span>);
div.hasClass(<span class="hljs-string">&apos;highlight&apos;</span>); <span class="hljs-comment">// false&#xFF0C; class&#x662F;&#x5426;&#x5305;&#x542B;highlight</span>
div.addClass(<span class="hljs-string">&apos;highlight&apos;</span>); <span class="hljs-comment">// &#x6DFB;&#x52A0;highlight&#x8FD9;&#x4E2A;class</span>
div.removeClass(<span class="hljs-string">&apos;highlight&apos;</span>); <span class="hljs-comment">// &#x5220;&#x9664;highlight&#x8FD9;&#x4E2A;class</span>
</code></pre>
<h3 id="&#x663E;&#x793A;&#x548C;&#x9690;&#x85CF;dom">&#x663E;&#x793A;&#x548C;&#x9690;&#x85CF;DOM</h3>
<p>&#x8981;&#x9690;&#x85CF;&#x4E00;&#x4E2A;DOM&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;CSS&#x7684;<code>display</code>&#x5C5E;&#x6027;&#x4E3A;<code>none</code>&#xFF0C;&#x5229;&#x7528;<code>css()</code>&#x65B9;&#x6CD5;&#x5C31;&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;&#x3002;&#x4E0D;&#x8FC7;&#xFF0C;&#x8981;&#x663E;&#x793A;&#x8FD9;&#x4E2A;DOM&#x5C31;&#x9700;&#x8981;&#x6062;&#x590D;&#x539F;&#x6709;&#x7684;<code>display</code>&#x5C5E;&#x6027;&#xFF0C;&#x8FD9;&#x5C31;&#x5F97;&#x5148;&#x8BB0;&#x4E0B;&#x6765;&#x539F;&#x6709;&#x7684;<code>display</code>&#x5C5E;&#x6027;&#x5230;&#x5E95;&#x662F;<code>block</code>&#x8FD8;&#x662F;<code>inline</code>&#x8FD8;&#x662F;&#x522B;&#x7684;&#x503C;&#x3002;</p>
<p>&#x8003;&#x8651;&#x5230;&#x663E;&#x793A;&#x548C;&#x9690;&#x85CF;DOM&#x5143;&#x7D20;&#x4F7F;&#x7528;&#x975E;&#x5E38;&#x666E;&#x904D;&#xFF0C;jQuery&#x76F4;&#x63A5;&#x63D0;&#x4F9B;<code>show()</code>&#x548C;<code>hide()</code>&#x65B9;&#x6CD5;&#xFF0C;&#x6211;&#x4EEC;&#x4E0D;&#x7528;&#x5173;&#x5FC3;&#x5B83;&#x662F;&#x5982;&#x4F55;&#x4FEE;&#x6539;<code>display</code>&#x5C5E;&#x6027;&#x7684;&#xFF0C;&#x603B;&#x4E4B;&#x5B83;&#x80FD;&#x6B63;&#x5E38;&#x5DE5;&#x4F5C;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> a = $(<span class="hljs-string">&apos;a[target=_blank]&apos;</span>);
a.hide(); <span class="hljs-comment">// &#x9690;&#x85CF;</span>
a.show(); <span class="hljs-comment">// &#x663E;&#x793A;</span>
</code></pre>
<p><em>&#x6CE8;&#x610F;</em>&#xFF0C;&#x9690;&#x85CF;DOM&#x8282;&#x70B9;&#x5E76;&#x672A;&#x6539;&#x53D8;DOM&#x6811;&#x7684;&#x7ED3;&#x6784;&#xFF0C;&#x5B83;&#x53EA;&#x5F71;&#x54CD;DOM&#x8282;&#x70B9;&#x7684;&#x663E;&#x793A;&#x3002;&#x8FD9;&#x548C;&#x5220;&#x9664;DOM&#x8282;&#x70B9;&#x662F;&#x4E0D;&#x540C;&#x7684;&#x3002;</p>
<h3 id="&#x83B7;&#x53D6;dom&#x4FE1;&#x606F;">&#x83B7;&#x53D6;DOM&#x4FE1;&#x606F;</h3>
<p>&#x5229;&#x7528;jQuery&#x5BF9;&#x8C61;&#x7684;&#x82E5;&#x5E72;&#x65B9;&#x6CD5;&#xFF0C;&#x6211;&#x4EEC;&#x76F4;&#x63A5;&#x53EF;&#x4EE5;&#x83B7;&#x53D6;DOM&#x7684;&#x9AD8;&#x5BBD;&#x7B49;&#x4FE1;&#x606F;&#xFF0C;&#x800C;&#x65E0;&#x9700;&#x9488;&#x5BF9;&#x4E0D;&#x540C;&#x6D4F;&#x89C8;&#x5668;&#x7F16;&#x5199;&#x7279;&#x5B9A;&#x4EE3;&#x7801;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x6D4F;&#x89C8;&#x5668;&#x53EF;&#x89C6;&#x7A97;&#x53E3;&#x5927;&#x5C0F;:</span>
$(<span class="hljs-built_in">window</span>).width(); <span class="hljs-comment">// 800</span>
$(<span class="hljs-built_in">window</span>).height(); <span class="hljs-comment">// 600</span>

<span class="hljs-comment">// HTML&#x6587;&#x6863;&#x5927;&#x5C0F;:</span>
$(<span class="hljs-built_in">document</span>).width(); <span class="hljs-comment">// 800</span>
$(<span class="hljs-built_in">document</span>).height(); <span class="hljs-comment">// 3500</span>

<span class="hljs-comment">// &#x67D0;&#x4E2A;div&#x7684;&#x5927;&#x5C0F;:</span>
<span class="hljs-keyword">var</span> div = $(<span class="hljs-string">&apos;#test-div&apos;</span>);
div.width(); <span class="hljs-comment">// 600</span>
div.height(); <span class="hljs-comment">// 300</span>
div.width(<span class="hljs-number">400</span>); <span class="hljs-comment">// &#x8BBE;&#x7F6E;CSS&#x5C5E;&#x6027; width: 400px&#xFF0C;&#x662F;&#x5426;&#x751F;&#x6548;&#x8981;&#x770B;CSS&#x662F;&#x5426;&#x6709;&#x6548;</span>
div.height(<span class="hljs-string">&apos;200px&apos;</span>); <span class="hljs-comment">// &#x8BBE;&#x7F6E;CSS&#x5C5E;&#x6027; height: 200px&#xFF0C;&#x662F;&#x5426;&#x751F;&#x6548;&#x8981;&#x770B;CSS&#x662F;&#x5426;&#x6709;&#x6548;</span>
</code></pre>
<p><code>attr()</code>&#x548C;<code>removeAttr()</code>&#x65B9;&#x6CD5;&#x7528;&#x4E8E;&#x64CD;&#x4F5C;DOM&#x8282;&#x70B9;&#x7684;&#x5C5E;&#x6027;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// &lt;div id=&quot;test-div&quot; name=&quot;Test&quot; start=&quot;1&quot;&gt;...&lt;/div&gt;</span>
<span class="hljs-keyword">var</span> div = $(<span class="hljs-string">&apos;#test-div&apos;</span>);
div.attr(<span class="hljs-string">&apos;data&apos;</span>); <span class="hljs-comment">// undefined, &#x5C5E;&#x6027;&#x4E0D;&#x5B58;&#x5728;</span>
div.attr(<span class="hljs-string">&apos;name&apos;</span>); <span class="hljs-comment">// &apos;Test&apos;</span>
div.attr(<span class="hljs-string">&apos;name&apos;</span>, <span class="hljs-string">&apos;Hello&apos;</span>); <span class="hljs-comment">// div&#x7684;name&#x5C5E;&#x6027;&#x53D8;&#x4E3A;&apos;Hello&apos;</span>
div.removeAttr(<span class="hljs-string">&apos;name&apos;</span>); <span class="hljs-comment">// &#x5220;&#x9664;name&#x5C5E;&#x6027;</span>
div.attr(<span class="hljs-string">&apos;name&apos;</span>); <span class="hljs-comment">// undefined</span>
</code></pre>
<p><code>prop()</code>&#x65B9;&#x6CD5;&#x548C;<code>attr()</code>&#x7C7B;&#x4F3C;&#xFF0C;&#x4F46;&#x662F;HTML5&#x89C4;&#x5B9A;&#x6709;&#x4E00;&#x79CD;&#x5C5E;&#x6027;&#x5728;DOM&#x8282;&#x70B9;&#x4E2D;&#x53EF;&#x4EE5;&#x6CA1;&#x6709;&#x503C;&#xFF0C;&#x53EA;&#x6709;&#x51FA;&#x73B0;&#x4E0E;&#x4E0D;&#x51FA;&#x73B0;&#x4E24;&#x79CD;&#xFF0C;&#x4F8B;&#x5982;&#xFF1A;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;test-radio&quot;</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;radio&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;test&quot;</span> <span class="hljs-attr">checked</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;1&quot;</span>&gt;</span>
</code></pre>
<p>&#x7B49;&#x4EF7;&#x4E8E;&#xFF1A;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;test-radio&quot;</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;radio&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;test&quot;</span> <span class="hljs-attr">checked</span>=<span class="hljs-string">&quot;checked&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;1&quot;</span>&gt;</span>
</code></pre>
<p><code>attr()</code>&#x548C;<code>prop()</code>&#x5BF9;&#x4E8E;&#x5C5E;&#x6027;<code>checked</code>&#x5904;&#x7406;&#x6709;&#x6240;&#x4E0D;&#x540C;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> radio = $(<span class="hljs-string">&apos;#test-radio&apos;</span>);
radio.attr(<span class="hljs-string">&apos;checked&apos;</span>); <span class="hljs-comment">// &apos;checked&apos;</span>
radio.prop(<span class="hljs-string">&apos;checked&apos;</span>); <span class="hljs-comment">// true</span>
</code></pre>
<p><code>prop()</code>&#x8FD4;&#x56DE;&#x503C;&#x66F4;&#x5408;&#x7406;&#x4E00;&#x4E9B;&#x3002;&#x4E0D;&#x8FC7;&#xFF0C;&#x7528;<code>is()</code>&#x65B9;&#x6CD5;&#x5224;&#x65AD;&#x66F4;&#x597D;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> radio = $(<span class="hljs-string">&apos;#test-radio&apos;</span>);
radio.is(<span class="hljs-string">&apos;:checked&apos;</span>); <span class="hljs-comment">// true</span>
</code></pre>
<p><code>prop()</code>&#x8FD4;&#x56DE;&#x503C;&#x66F4;&#x5408;&#x7406;&#x4E00;&#x4E9B;&#x3002;&#x4E0D;&#x8FC7;&#xFF0C;&#x7528;<code>is()</code>&#x65B9;&#x6CD5;&#x5224;&#x65AD;&#x66F4;&#x597D;.</p>
<p>&#x7C7B;&#x4F3C;&#x7684;&#x5C5E;&#x6027;&#x8FD8;&#x6709;<code>selected</code>&#xFF0C;&#x5904;&#x7406;&#x65F6;&#x6700;&#x597D;&#x7528;<code>is(&apos;:selected&apos;)</code>&#x3002;</p>
<h3 id="&#x64CD;&#x4F5C;&#x8868;&#x5355;">&#x64CD;&#x4F5C;&#x8868;&#x5355;</h3>
<p>&#x5BF9;&#x4E8E;&#x8868;&#x5355;&#x5143;&#x7D20;&#xFF0C;jQuery&#x5BF9;&#x8C61;&#x7EDF;&#x4E00;&#x63D0;&#x4F9B;<code>val()</code>&#x65B9;&#x6CD5;&#x83B7;&#x53D6;&#x548C;&#x8BBE;&#x7F6E;&#x5BF9;&#x5E94;&#x7684;<code>value</code>&#x5C5E;&#x6027;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">/*
    &lt;input id=&quot;test-input&quot; name=&quot;email&quot; value=&quot;&quot;&gt;
    &lt;select id=&quot;test-select&quot; name=&quot;city&quot;&gt;
        &lt;option value=&quot;BJ&quot; selected&gt;Beijing&lt;/option&gt;
        &lt;option value=&quot;SH&quot;&gt;Shanghai&lt;/option&gt;
        &lt;option value=&quot;SZ&quot;&gt;Shenzhen&lt;/option&gt;
    &lt;/select&gt;
    &lt;textarea id=&quot;test-textarea&quot;&gt;Hello&lt;/textarea&gt;
*/</span>
<span class="hljs-keyword">var</span>
    input = $(<span class="hljs-string">&apos;#test-input&apos;</span>),
    select = $(<span class="hljs-string">&apos;#test-select&apos;</span>),
    textarea = $(<span class="hljs-string">&apos;#test-textarea&apos;</span>);

input.val(); <span class="hljs-comment">// &apos;test&apos;</span>
input.val(<span class="hljs-string">&apos;abc@example.com&apos;</span>); <span class="hljs-comment">// &#x6587;&#x672C;&#x6846;&#x7684;&#x5185;&#x5BB9;&#x5DF2;&#x53D8;&#x4E3A;abc@example.com</span>

select.val(); <span class="hljs-comment">// &apos;BJ&apos;</span>
select.val(<span class="hljs-string">&apos;SH&apos;</span>); <span class="hljs-comment">// &#x9009;&#x62E9;&#x6846;&#x5DF2;&#x53D8;&#x4E3A;Shanghai</span>

textarea.val(); <span class="hljs-comment">// &apos;Hello&apos;</span>
textarea.val(<span class="hljs-string">&apos;Hi&apos;</span>); <span class="hljs-comment">// &#x6587;&#x672C;&#x533A;&#x57DF;&#x5DF2;&#x66F4;&#x65B0;&#x4E3A;&apos;Hi&apos;</span>
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="查找和过滤.html" class="navigation navigation-prev " aria-label="Previous page: 查找和过滤">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="修改DOM结构.html" class="navigation navigation-next " aria-label="Next page: 修改DOM结构">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"操作DOM","level":"1.5.2","depth":2,"next":{"title":"修改DOM结构","level":"1.5.2.1","depth":3,"path":"Jquery/修改DOM结构.md","ref":"Jquery/修改DOM结构.md","articles":[]},"previous":{"title":"查找和过滤","level":"1.5.1.2","depth":3,"path":"Jquery/查找和过滤.md","ref":"Jquery/查找和过滤.md","articles":[]},"dir":"ltr"},"config":{"plugins":["lunr","pageview-count","chapter-fold","back-to-top-button","code","hide-element","-sharing","sharing-plus","custom-favicon"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"chapter-fold":{},"search":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"lunr":{"ignoreSpecialCharacters":false,"maxIndexSize":1000000},"code":{"copyButtons":true},"hide-element":{"elements":[".gitbook-link"]},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"favicon":"js.ico","back-to-top-button":{},"pageview-count":{},"custom-favicon":{},"sharing":{"qq":true,"all":["douban","facebook","google","instapaper","linkedin","twitter","weibo","messenger","qq","qzone","viber","whatsapp"],"douban":true,"facebook":true,"weibo":true,"twitter":true,"pocket":true,"google":true,"qzone":true},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"Veng","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"JavaScript学习","language":"zh-hans","gitbook":"*","description":"javaScript的学习笔记"},"file":{"path":"Jquery/操作DOM.md","mtime":"2020-12-10T02:10:04.958Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-12-10T03:00:51.663Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-pageview-count/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-hide-element/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

